﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="XnReader.WinRT.Book"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XnReader.WinRT"
    xmlns:common="using:XnReader.WinRT.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Controlx="using:XnReader.WinRT.Controlx"
    mc:Ignorable="d">

    <Page.Resources>
        <CollectionViewSource x:Name="cvs2" />
    </Page.Resources>
    <common:LayoutAwarePage.TopAppBar>
        <AppBar x:Name="barNav" Height="140" Background="#E5040404" >
            <Controlx:NavDx x:Name="navTop" Margin="60,0,40,0" />
        </AppBar>
    </common:LayoutAwarePage.TopAppBar>
    <common:LayoutAwarePage.BottomAppBar>
        <AppBar Height="90" Background="#E5040404" >
            <Controlx:CommandDx x:Name="tlBottom" />
        </AppBar>
    </common:LayoutAwarePage.BottomAppBar>

    <!--
        此网格用作定义以下两行的页的根面板:
        * 第 0 行包含后退按钮和页标题
        * 第 1 行包含页布局的其余部分
    -->
    <Grid DataContext="{Binding Article}" Style="{StaticResource LayoutRootStyle}">
        <Grid.Background>
            <ImageBrush ImageSource="/Assets/background_default.png"/>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!-- 在大多数视图状态中使用的水平滚动网格-->
        <ProgressRing Width="80" Height="80" x:Name="pbLoading"   Grid.RowSpan="2" IsActive="True"></ProgressRing>
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Items In Group"
            TabIndex="1"
            Grid.RowSpan="2"
            Padding="120,136,120,50"
            ItemsSource="{Binding Source={StaticResource cvs2}}"
            ItemTemplate="{StaticResource dtBookWebsiteItem}"
            ItemClick="ItemGridViewItemClick"
            SelectionMode="None"
            IsItemClickEnabled="True"
            IsSwipeEnabled="false" >
            <GridView.Header>
                <StackPanel Orientation="Vertical" Width="400">
                    <StackPanel Orientation="Horizontal" Margin="0,10,0,0" >
                        <Border Width="120" Height="150" BorderBrush="Black" BorderThickness="1">
                            <Image x:Name="imgCover" Source="Assets/defaultcover.jpg" ></Image>
                        </Border>
                        <StackPanel Orientation="Vertical" Margin="20,0,0,0">
                            <TextBlock Text="{Binding articlename}" Height="40" Style="{StaticResource SubheaderTextStyle}"/>
                            <StackPanel Orientation="Horizontal" Height="30">
                                <TextBlock Text="小说作者:"  Style="{StaticResource CaptionH3}"/>
                                <TextBlock Text="{Binding author}"  Style="{StaticResource TextH3}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Height="30">
                                <TextBlock Text="小说类别:" Style="{StaticResource CaptionH3}"/>
                                <TextBlock Text="{Binding sortname}"  Style="{StaticResource TextH3}"/>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Height="30">
                                <TextBlock Text="当前进度:" Style="{StaticResource CaptionH3}"></TextBlock>
                                <TextBlock Text="{Binding writeprogress}"  Style="{StaticResource TextH3}"></TextBlock>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal" Height="30">
                                <TextBlock Text="最新更新:" Style="{StaticResource CaptionH3}"></TextBlock>
                                <TextBlock Text="{Binding lastupdate}" Style="{StaticResource TextH3}"></TextBlock>
                            </StackPanel>
                        </StackPanel>

                    </StackPanel>
                    <TextBlock Text="内容简介" FontSize="28" Margin="0,20,0,0" />
                    <TextBlock Text="{Binding intro}" Style="{StaticResource BodyTextStyle}"/>
                </StackPanel>
            </GridView.Header>
            <GridView.ItemContainerStyle>
                <Style TargetType="FrameworkElement">
                    <Setter Property="Margin" Value="52,0,0,10"/>
                </Style>
            </GridView.ItemContainerStyle>
        </GridView>
        <!-- 垂直滚动列表仅在对齐后使用-->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemListView"
            AutomationProperties.Name="Items In Group"
            TabIndex="1"
            Grid.Row="1"
            Visibility="Collapsed"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource cvs2}}"
            ItemTemplate="{StaticResource dtBookWebsiteItem}"
            SelectionMode="None"
            IsSwipeEnabled="false" 
            IsItemClickEnabled="True"
            ItemClick="ItemGridViewItemClick">
            <ListView.Header>
                <StackPanel>
                    <TextBlock Text="{Binding articlename}" Margin="10,0,18,20" Style="{StaticResource TitleTextStyle}" MaxHeight="60"/>
                    <!--<Border Width="120" Height="150" BorderBrush="Black" BorderThickness="1">
                        <Image x:Name="imgCover1" Source="Assets/defaultcover.jpg" ></Image>
                    </Border>-->
                    <TextBlock Margin="10,20,18,30" Text="{Binding intro}" Style="{StaticResource BodyTextStyle}"/>
                </StackPanel>
            </ListView.Header>
        </ListView>
        <!-- 后退按钮和页标题-->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="40"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button Grid.RowSpan="2" x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <StackPanel  Grid.RowSpan="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                <Image Source="Assets/logo_small.png"  Width="250" Height="80" Margin="0"></Image>
            </StackPanel>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- 视觉状态反映应用程序的视图状态-->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- 整页采用较窄的 100 像素页边距约定(纵向)-->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="navTop" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="5,0,5,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,136,86,56"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    对齐后，后退按钮和标题的样式将有所不同，并且列表表示形式将被
                    所有视图状态中显示的网格所替代
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>-->
                        <!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="barNav" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>-->
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
